const path = require('path')

// 导入api
const homeModel = require(path.join(__dirname,"../model/homeModel.js"))

// 渲染首页
exports.index = (req,res,next) => {
    Promise.all([homeModel.getSlides(),homeModel.getLikes()]).then(results => {
        // 给模版赋值
        res.locals.sliders = results[0]
        res.locals.likes = results[1]

        // 渲染首页并且返回
        res.render(path.join(__dirname,"../views/home.art"))
    }).catch(err=>next(err))
}

// 返回Likes数据
exports.getLikes = (req,res,next) => {
    homeModel.getLikes().then(result=>res.json(result)).catch(err=>next(err))
}